import java.io.File
import java.lang.management.ManagementFactory
import java.net.{InetAddress, Socket}
import java.nio.file.Files
import java.util.concurrent.{Callable, FutureTask}

import org.apache.commons.io.FileUtils
import tool.Tool
import tool.Tool.workSpace
import utils.Utils

import scala.collection.mutable.ArrayBuffer
import scala.concurrent.{CancellationException, ExecutionContext, Future, Promise}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.sys.process.Process
import scala.util.Try
import scala.collection.JavaConverters._


/**
 * Created by yz on 2019/3/21
 */
object Test {

  def main(args: Array[String]): Unit = {

    //    val command =
    //      s"""
    //         |set T=%TEMP%\\sthUnique.tmp
    //         |wmic process where (Name="WMIC.exe" AND CommandLine LIKE "%%%TIME%%%") get ParentProcessId /value | find "ParentProcessId" >%T%
    //         |set /P A=<%T%
    //         |set PID=%A:~16%
    //         |echo %PID% >pid.txt
    //         |live_boost-1.0/bin/live_boost.bat
    //           """.stripMargin
    //    val execCommand=Utils.callScript(workSpace, ArrayBuffer(command))
    //    println(execCommand.getErrStr)
//    val projectDir=new File("C:\\workspaceForIDEA\\live_forest_h2")
    val projectDir=new File("C:\\workspaceForIDEA\\live_forest_app")
//    val projectDir = new File("C:\\workspaceForIDEA\\live_fat_h2_app")
//    val suffix = ".scala"
    val suffix = ".java"
//    val dirNames=List("server/app","client/src","shared/src")
        val dirNames = List("src/main/scala")
    dirNames.foreach { dirName =>
      getLines(new File(projectDir, dirName), suffix)
    }
    println(arrayBuffer.size)

  }

  val arrayBuffer = ArrayBuffer[String]()

  def getLines(file: File, suffix: String): ArrayBuffer[String] = {
    for (f <- file.listFiles()) {
      if (f.isDirectory) {
        getLines(f, suffix)
      } else {
        val lines = if (f.getName.endsWith(suffix)) {
          arrayBuffer ++= FileUtils.readLines(f).asScala
        } else arrayBuffer

      }
    }
    arrayBuffer
  }

}
